Skip to content

Add and use readLE/writeLE helpers#8470

Merged
kripken merged 1 commit intoWebAssembly:mainfrom
sertonix:be
Mar 20, 2026
Merged

Add and use readLE/writeLE helpers#8470
kripken merged 1 commit intoWebAssembly:mainfrom
sertonix:be

Conversation

@sertonix
Copy link
Contributor

@sertonix sertonix commented Mar 15, 2026

According to godbolt.org these functions optimize to a simple *(T *)ptr in many cases while ensuring that memory alignment requirements and endianess does not effect the behavior.

The unroll pragma is needed for GCC to properly optimize the code.

The approach of using bit shifts is also used in multiple other parts of binaryen (eg. WasmBinaryReader::getInt16) but usage of the helper function doesn't seem to be that easy there.

Ref #2983

@sertonix sertonix marked this pull request as ready for review March 15, 2026 01:35
@sertonix sertonix force-pushed the be branch 2 times, most recently from dd5afc4 to caaf83e Compare March 16, 2026 19:38
@kripken
Copy link
Member

kripken commented Mar 19, 2026

Have you confirmed these fix the big-endian errors?

@sertonix
Copy link
Contributor Author

There are still test failures but I think more tests pass with this change. I haven't done a direct comparison of tests failing with and without this change yet. Some of my test logs can be found here: https://gitlab.alpinelinux.org/sertonix/aports/-/merge_requests/179

@sertonix
Copy link
Contributor Author

I haven't done a direct comparison of tests failing with and without this change yet.

I did that now and the diff look promising:

-[ 180 failures! ]
+[ 29 failures! ]

patched.log
unpatched.log

@sertonix sertonix requested a review from a team as a code owner March 20, 2026 18:54
@sertonix sertonix requested review from kripken and removed request for a team March 20, 2026 18:54
Copy link
Member

@kripken kripken left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good aside from a style nit

According to godbolt.org these functions optimize to a simple *(T *)ptr
in many cases while ensuring that memory alignment requirements and
endianess does not effect the behavior.

The unroll pragma is needed for GCC to properly optimize the code.

The approach of using bit shifts is also used in multiple other parts
of binaryen (eg. WasmBinaryReader::getInt16) but usage of the helper
function doesn't seem to be that easy there.

Ref WebAssembly#2983
@kripken
Copy link
Member

kripken commented Mar 20, 2026

Have you fuzzed this? I'm running it now locally.

@sertonix
Copy link
Contributor Author

Have you fuzzed this?

I don't think so. I ran whatever check.py runs by default

@kripken
Copy link
Member

kripken commented Mar 20, 2026

I don't see any fuzz issues.

@kripken kripken merged commit 0e2ee37 into WebAssembly:main Mar 20, 2026
16 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants